<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>添加或编辑界面</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body>
<div class="page-content-wrap clearfix">
    <form class="layui-form" id="tool">
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;应用名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" required lay-verify="required" placeholder="请输入应用名称" value="${wxApplyUse.name}" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-pop-tworow">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;应用封面：</label>
                        <!--单图片开始-->
                        <div class="layui-input-block cy-uploadpic-ctn" id="coverImage" style=" float:left;margin-left:0!important;position:relative;">

                        </div>
                        <!--单图片结束-->
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;后台地址：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="webPath" id="webPath"  value="${wxApplyUse.webPath}" lay-verify="required" placeholder="请输入后台地址" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;手机端地址：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phonePath" id="phonePath" value="${wxApplyUse.phonePath}" lay-verify="required" placeholder="请输入手机端地址" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;费用元/年：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="money" value="${wxApplyUse.money}" lay-verify="required" placeholder="请输入费用元/年" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;试用时间/天：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="useDay" value="${wxApplyUse.useDay}" lay-verify="required" placeholder="请输入试用时间/天" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;行业分类：</label>
                        <div class="layui-input-inline w440">
                            <#list categoryList as category>
                            <input type="checkbox" name="categoryList" value="${category.id}" lay-skin="primary" title="${category.name}"
                            <#list applyUseCategoryList as applyUseCategory> <#if applyUseCategory.categoryId=category.id>checked</#if></#list>>
                            </#list>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;应用类型：</label>
                        <div class="layui-input-inline">
                            <select name="type" id="type" lay-verify="required"></select>
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;点击量：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="clicks" value="${wxApplyUse.clicks}" lay-verify="required|orderNum" placeholder="请输入点击量" autocomplete="off"
                                   class="layui-input" maxlength="11">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;状态类型：</label>
                        <div class="layui-input-inline">
                            <select name="status" id="status" lay-verify="required"></select>
                        </div>
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;版本号：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="version" value="${wxApplyUse.version}" lay-verify="required" placeholder="请输入版本号" autocomplete="off"
                                   class="layui-input" maxlength="200">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red">*</span>&nbsp;应用状态：</label>
                        <div class="layui-input-inline">
                            <select name="applyUseStatus" id="applyUseStatus" lay-verify="required"></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red"></span>&nbsp;更新记录：</label>
                        <div class="layui-input-block">
                            <textarea id="updateRecord" autocomplete="off" placeholder="请输入更新记录">${wxApplyUse.updateRecord}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="red"></span>&nbsp;描述：</label>
                        <div class="layui-input-block">
                            <textarea id="description" autocomplete="off" placeholder="请输入描述">${wxApplyUse.description}</textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-pop-btn">
            <div class="layui-input-block" style="margin-left: 0px !important;text-align: center">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">提交</button>
                <button type="button" id="cancel" class="layui-btn layui-btn-primary">取消</button>
                <button type="button" style="display: none;" id="save" class="layui-btn layui-btn-primary"></button>
            </div>
        </div>
    </form>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['jquery', 'form', 'page', 'fileUtil', 'baseutil','dialog'], function () {
        var $ = layui.jquery,
            form = layui.form,
            page = layui.page,
            fileUtil = layui.fileUtil,
            baseutil = layui.baseutil;
            dialog = layui.dialog;

        //初始化附件控件
        fileUtil.uploadImage('coverImage', "wx/wxApplyUse", "${wxApplyUse.coverImage}");

        form.verify({
            orderNum: function (value) {
                var num = /^[1-9]\d*$/;
                if (!num.test(value)) {
                    return '排序输入不正确';
                }
            }
        });

        page.initDict('wx_apply_use_type,base_status,wx_apply_use_status', function (dictData) {
            page.showDict($("#status"), page.aceeptDictContentList(dictData, 'base_status'), "请选择", '${wxApplyUse.status}');
            page.showDict($("#type"), page.aceeptDictContentList(dictData, 'wx_apply_use_type'), "请选择", '${wxApplyUse.type}');
            page.showDict($("#applyUseStatus"), page.aceeptDictContentList(dictData, 'wx_apply_use_status'), "请选择", '${wxApplyUse.applyUseStatus}');


        });

        //KnifeZ富文本
        var updateRecordIndex = baseutil.layeditKnifezBuild("updateRecord", 300);

        //KnifeZ富文本
        var descriptionIndex = baseutil.layeditKnifezBuild("description", 300);

        //监听提交
        form.on('submit(submitBtn)', function (data) {
            var categoryIds = [];//接收对象
            var r = document.getElementsByName("categoryList");
            for (var i = 0; i < r.length; i++) {
                if (r[i].checked) {
                    categoryIds.push(r[i].value);
                }
            }
            if (categoryIds == null || categoryIds.length <= 0) {
                dialog.msg("请选择行业分类");
                return false;
            }
            var webPath=$("#webPath").val();
            if(webPath !=null && webPath !=""){
                data.field.webPath =  encodeURIComponent(webPath);
            }
            var coverImage = $('input[name=coverImage]').val();
            if (coverImage == null || coverImage.length <= 0) {
                dialog.msg("请上传应用封面");
                return false;
            }

            var phonePath=$("#phonePath").val();
            if(phonePath !=null && phonePath !=""){
                data.field.phonePath =  encodeURIComponent(phonePath);
            }
            data.field.categoryIds = categoryIds.join(",");
            data.field.updateRecord = baseutil.layeditBuildContent(updateRecordIndex);
            data.field.description = baseutil.layeditBuildContent(descriptionIndex);
            data.field.id = '${wxApplyUse.id}';
            baseutil.post("/wx/wxapplyuse/addOrUpdate", data.field, function () {
                $("#save").click();
            });
            return false;
        });
    });
</script>
</body>
</html>